﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApi.Bill.Biz;
using WebApi.Models;

namespace WebApi.Controllers
{
    public class SkillClassifyController : BaseController
    {


        #region 获取逃生技巧列表 List
        /// <summary>
        /// 获取逃生技巧列表
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult<SkillClassifyModel> List()
        {
            ResponseDataNews res = new ResponseDataNews();

            try
            {
                List<NewsGetData> data = BizBase.Get<BizSkillClassify>().SkillList();
                res.code = 200;
                res.msg = "查询成功";
                res.rows = data;
                res.total = Convert.ToString(data.Count());


                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                return this.ControllerExHandler(res, "List", ex);
            }
        }


        #endregion

        #region 获取逃生技巧列表 List
        /// <summary>
        /// 获取逃生技巧列表
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult<SkillClassifyModel> CategoryList()
        {
            ResponseDataNews res = new ResponseDataNews();

            try
            {
                List<CategoryNewsModel> data = BizBase.Get<BizSkillClassify>().List();
                if (data != null && data.Count > 0)
                {
                    res.code = 200;
                    res.msg = "查询成功";
                    res.rows = data.Select(x => new { id = x.categoryID, date = x.category });
                    res.total = Convert.ToString(data.Count());
                }
                else
                {
                    res.code = 200;
                    res.msg = "查询成功";
                    res.rows = data;
                    res.total = "0";
                }


                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                return this.ControllerExHandler(res, "List", ex);
            }
        }


        #endregion

    }
}
